﻿/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 7/29/2009
 * Time: 2:41 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using popLib;
using System.IO;


namespace GenerateAccessTable
{
	class Program
	{
		static string _namespace = "";
		static string _connectionHolder = "";
		static string _executeFiles 	= "";
		static string _dataQueryPath 	= "";
		static bool _generateSettingClass = false;
		static bool _generateDataQuery = false;
		
		
		static string file_config = FileLib.getFullPath( "config.ini" );
		static Profile config;
		static string section = "Application";	
		
		
		public static void main(string[] args)
		{
			config = ProfileLib.initProfile( ProfileLib.ProfileType.Ini, file_config );
						
			_namespace 		  		= config.getValue( section, "Namespace", "DEMO_NAMESPACE" );
			_connectionHolder 		= config.getValue( section, "ConnectionHolder", "GLOBAL" );
			_generateSettingClass   = config.getBoolean( section, "GenerateSettingClass", false );
			_generateDataQuery		= config.getBoolean( section, "GenerateDataQuery", false );
			_dataQueryPath			= config.getValue( section, "DataQueryPath", "" );
			_executeFiles			= config.getValue( section, "ExecuteFiles", "*.txt" );
			
			
			//execute file using argurements
			if( args.Length > 0 ){ 
				foreach( string file in args )
					executePattern( file );
			}
			//execute file in "ExecuteFiles" value
			else {
				string[] patterns = StringLib.splitByAny( _executeFiles , ";,|");
				foreach( string pattern in patterns ){
					executePattern( pattern );
				}
			}
			
			//gen dataquery
			if( _generateDataQuery ){
				string path = (Path.IsPathRooted(_dataQueryPath)) ? _dataQueryPath : FileLib.getFullPath( _dataQueryPath );
				path = Path.Combine( path, "DataQuery.cs" );
				FileLib.writeFile( path, createDataQueryClass() );
			}			
		}
		
		public static void executePattern(string pattern){
			if( pattern.IndexOf("*") >= 0 ){
				string path  = Path.IsPathRooted( pattern ) ? Path.GetDirectoryName( pattern ) : Path.GetDirectoryName( FileLib.getFullPath( pattern ) );
				string searchPattern = Path.GetFileName( pattern );
				string[] files = FileLib.getFileList( path, searchPattern, false, FileLib.SearchOption.FileOnly );
				foreach( string file in files )
					executeTable( file );
			}else if( File.Exists( pattern ) ) {
				executeTable( pattern );
			}
		}
		
		public static void executeTable(string file){
			try{
				string table		= Path.GetFileNameWithoutExtension(file);
				string path 		= Path.GetDirectoryName(file);
				string[] columns    = StringLib.splitByAny( FileLib.readFile(file), new string[]{"\r\n"} );
				
				string objClass		= Path.Combine( path, table+".cs" );
				string DBClass		= Path.Combine( path, table+"DB.cs" );
				string ConfClass	= Path.Combine( path, table+"CFG.cs" );
				
				FileLib.writeFile( objClass, createInstanceClass( table, columns, false ) );				
				FileLib.writeFile( DBClass, createDataHandleClass( table, columns ) );
				
				if( _generateSettingClass ) FileLib.writeFile( ConfClass, createInstanceClass( table, columns, true ) );
			}catch(Exception ex){FormLib.alert(ex);}
		}
		
		
		
		public static string createInstanceClass(string table, string[] columns, bool isSettingClass){
			string properties = "";
			string constructor = "";
			string section = "SECTION";
			
			foreach( string col in columns ){
				if( StringLib.isValid(col) ){
					string[] parts = StringLib.splitByAny( col, "\t|" );
					
					string name = parts[0];
					name = (name == table) ? name+"_1" : name;
					string type = parts[1];
					
					section = parts.Length > 2 && StringLib.isValid(parts[2])? parts[2] : section;
					string defaultValue = parts.Length > 3 ? parts[3] : "";
					string func = "config.getValue( \""+section+"\", \""+name+"\", \""+defaultValue+"\" );";
					if( defaultValue.ToLower().IndexOf("<br>") >= 0 )
						func = "config.getValue( \""+section+"\", \""+name+"\", \""+defaultValue.Replace("<BR>","<br>")+"\" ).Replace(\"<br>\",\"\\r\\n\");";
					
					switch( type.ToLower() ){
						case "autonumber":
						case "number":
							type = "int"; 
							defaultValue = StringLib.isValid(defaultValue) ? defaultValue : "0";
							func = "config.getInt( \""+section+"\", \""+name+"\", "+defaultValue+" );";
							break;
									
						case "yes/no": 
							type = "bool";
							defaultValue = StringLib.isValid(defaultValue) ? defaultValue : "true";
							func = "config.getBoolean( \""+section+"\", \""+name+"\", "+defaultValue+" );";
							break;
						
						case "date/time": 
							type = "DateTime";							
							break;
						
						case "Memo": 
						case "text":
							type = "string"; break;
							
						case "double":
							defaultValue = StringLib.isValid(defaultValue) ? defaultValue : "0";
							func = "config.getDouble( \""+section+"\", \""+name+"\", "+defaultValue+" );";
							break;
					}
					
					properties += "\t\tprivate "+type+" _"+name+";\r\n";
					properties += "\t\tpublic "+type+" "+name+"{ get{return _"+name+";} set{_"+name+" = value;} }\r\n\r\n";
					
					constructor += "\t\t\t_"+name+"\t\t= "+func + "\r\n";
				}
			}
			
			#region whole class content
			string classstr = @"using System;

namespace "+_namespace+@"
{
	/// <summary>
	/// Description of "+table+@".
	/// </summary>
	public class "+table+@"
	{		
"+properties+@"
	}
}";
			if( isSettingClass )
				classstr = @"using System;
using popLib;

namespace "+_namespace+@"
{
	/// <summary>
	/// Description of "+table+@".
	/// </summary>
	public class "+table+@"
	{	
		private static "+table+@" _"+table.ToLower()+@";
		public static string file_config  = FileLib.getFullPath(""config\\"+table+@".ini"");
		
		public static "+table+@" Singleton(){
			if( _"+table.ToLower()+@" == null )
				_"+table.ToLower()+@" = new "+table+@"(file_config);
			return _"+table.ToLower()+@";
		}
		
		private static Profile config;
		public "+table+@"(string file_config){
			config = ProfileLib.initProfile( ProfileLib.ProfileType.Ini, file_config );
			reload();
		}
		
		public void reload(){
"+constructor+@"
		}
		
"+properties+@"
	}
}";
			#endregion		
						
			return classstr;
		}
		
		public static string createDataHandleClass(string table, string[] columns){
			
			string pk_var = table.ToLower() + "Id";
			string pk_name = columns[0].Split('\t')[0];
			
			string paramStr = "";
			string paramValueStr = "";
			
			string paramStrUpdate = "";
			string pk_StrUpdate   = " [" + pk_name + "]=@" + pk_name;
			
			int index = -1;
			string storeValue = "";
			
			string initParam = "";
			string initParamExtent = "";
			
			
			
			foreach( string col in columns ){
				string name = col.Split('\t')[0];
				name = (name == table) ? name+"_1" : name;
				string type = col.Split('\t')[1];
				
				if( name != pk_name ){
					paramStr  		+= " ["+name.Replace("_1","")+"],";
					paramValueStr   += " @"+name+",";
				}
				
				if( name != pk_name )
					paramStrUpdate += " [" + name + "]=@" + name + ",";
				
				
				
				index++;
				switch( type.ToLower() ){
					case "autonumber":
					case "number": 
					case "int": 
					case "int16":
					case "int32":
					case "int64":
						if(type.ToLower() == "int16")
							storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetInt16("+index+");\r\n";
						else if(type.ToLower() == "int64")
							storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetInt64("+index+");\r\n";
						else storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetInt32("+index+");\r\n";
						
						if( name == pk_name )
							initParamExtent = "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Integer).Value = "+table.ToLower()+"."+name+";\r\n";
						else initParam += "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Integer).Value = "+table.ToLower()+"."+name+";\r\n";
						
						break;
					
					case "double":
						storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetDouble("+index+");\r\n"; 
						
						if( name == pk_name )
							initParamExtent = "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Double).Value = "+table.ToLower()+"."+name+";\r\n";
						else initParam += "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Double).Value = "+table.ToLower()+"."+name+";\r\n";
						
						break;	
								
					case "yes/no": 
						storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetBoolean("+index+");\r\n"; 
						
						if( name == pk_name ) initParamExtent = "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Boolean).Value = "+table.ToLower()+"."+name+";\r\n";
						else initParam += "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Boolean).Value = "+table.ToLower()+"."+name+";\r\n";
						break;
					
					case "date/time": 
						storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetDateTime("+index+");\r\n"; 
						
						if( name == pk_name ) initParamExtent = "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Date).Value = "+table.ToLower()+"."+name+";\r\n";
						else initParam += "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.Date).Value = "+table.ToLower()+"."+name+";\r\n";
						break;
					
					case "Memo": 
					case "text":
					default:
						storeValue += "\t\t\t\t\tcomtmp."+name+" = dr.GetString("+index+");\r\n"; 
						if( name == pk_name ) initParamExtent = "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.VarChar).Value = "+table.ToLower()+"."+name+";\r\n";
						else initParam += "\t\t\tsqlCommand1.Parameters.Add(\"@"+name+"\", OleDbType.VarChar).Value = "+table.ToLower()+"."+name+";\r\n";
						break;
				}
			}
			
			//remove comma character at the end of string.
			paramStr = paramStr.Substring(0, paramStr.Length-1 );
			paramValueStr = paramValueStr.Substring(0, paramValueStr.Length-1 );
			paramStrUpdate = paramStrUpdate.Substring(0, paramStrUpdate.Length-1 );
			
			
			#region QueryRecords
			string content = @"\t\tpublic DataSet QueryRecords(string []columns, string condition)
		{
			try{
				DataQuery query = new DataQuery(columns, """+table+@""", null, condition);
				query.ExecuteQuery();
				return query.GetDataSet();
			}catch(Exception ex){
				DataQuery.DBErrorReport( ex, """+table+@"DB.QueryRecords"" );
				return null;
			}
		}\r\n\r\n";
			#endregion
				
			#region DeleteById
			content += @"\t\tpublic bool DeleteById(string "+pk_var+@")
		{
			try{
				sqlCommand1 = new OleDbCommand();
				sqlCommand1.CommandText = @""DELETE FROM "+table+@" WHERE "+pk_name+@"="" + "+pk_var+@";				
				lock("+_connectionHolder+@".sqlConnection){
					sqlCommand1.Connection = "+_connectionHolder+@".sqlConnection;
					"+_connectionHolder+@".sqlConnection.Open();
					sqlCommand1.ExecuteNonQuery();
					"+_connectionHolder+@".sqlConnection.Close();
				}
			}catch(Exception ex){
				"+_connectionHolder+@".sqlConnection.Close();
				DataQuery.DBErrorReport( ex, """+table+@"DB.DeleteById"" );
				return false;
			}
			return true;
		}\r\n\r\n";
			#endregion
			
			#region NewRecord
			content += @"\t\tpublic bool NewRecord("+table+" "+table.ToLower()+@")
		{
			try{
				sqlCommand1 = new OleDbCommand();
				sqlCommand1.CommandText = @""INSERT INTO "+table+@"("+paramStr+@") VALUES ("+paramValueStr+@")"";
				SaveRecord("+table.ToLower()+@");
			}catch(Exception ex){
				DataQuery.DBErrorReport( ex, """+table+@"DB.NewRecord"" );
				return false;
			}
			return true;
		}\r\n\r\n";
			#endregion
			
			#region UpdateRecord			
			content += @"\t\tpublic bool UpdateRecord("+table+" "+table.ToLower()+@")
		{
			try{
				sqlCommand1 = new OleDbCommand();
				sqlCommand1.CommandText = @""UPDATE "+table+@" SET "+paramStrUpdate+@" WHERE "+pk_StrUpdate+@""";
				SaveRecord("+table.ToLower()+@");
			}catch(Exception ex){
				DataQuery.DBErrorReport( ex, """+table+@"DB.UpdateRecord"" );				
				return false;
			}
			return true;
		}\r\n\r\n";
			#endregion
			
			#region GetDetailsById
			content += @"\t\tpublic "+table+@" GetDetailsById(string "+pk_var+@")
		{
			"+table+" comtmp = new "+table+@"();
			sqlCommand1 = new OleDbCommand();
			sqlCommand1.CommandText = @""SELECT * from "+table+@" WHERE "+pk_name+@"="" + "+pk_var+@";
			lock("+_connectionHolder+@".sqlConnection){
				try{
					sqlCommand1.Connection = "+_connectionHolder+@".sqlConnection;
					"+_connectionHolder+@".sqlConnection.Open();
					OleDbDataReader dr = sqlCommand1.ExecuteReader();
					dr.Read();
					
"+storeValue+@"
					
					"+_connectionHolder+@".sqlConnection.Close();						
					return comtmp;
				}catch(Exception ex){
					DataQuery.DBErrorReport( ex, """+table+@"DB.GetDetailsById"" );
					"+_connectionHolder+@".sqlConnection.Close();
					return null;
				}
			}
		}\r\n\r\n";
			#endregion
			
			#region SaveRecord
			content += @"\t\tprivate bool SaveRecord("+table+" "+table.ToLower()+@")
		{
"+initParam+@"
			if( sqlCommand1.CommandText.StartsWith(""UPDATE"") )
	"+initParamExtent+@"
						
			try{
				lock("+_connectionHolder+@".sqlConnection){
					sqlCommand1.Connection = "+_connectionHolder+@".sqlConnection;
					"+_connectionHolder+@".sqlConnection.Open();
					sqlCommand1.ExecuteNonQuery();
					"+_connectionHolder+@".sqlConnection.Close();
				}
			}catch(Exception ex){
				DataQuery.DBErrorReport( ex, """+table+@"DB.SaveRecord"" );
				"+_connectionHolder+@".sqlConnection.Close();
				return false;
			}
			return true;
		}\r\n\r\n";
			#endregion
			
			#region finally text
			content = @"using System;
using System.Data;
using System.Data.OleDb;
using popLib;

namespace "+_namespace+@"
{
	/// <summary>
	/// Description of "+table+@"DB.
	/// </summary>
	public class "+table+@"DB
	{
		private OleDbCommand sqlCommand1;

"+content+@"
	}
}";
			#endregion
			
			return content.Replace("\\r","\r").Replace("\\n","\n").Replace("\\t","\t");
		}
	
		public static string createDataQueryClass(){
			#region class DataQuery
			return @"using System;
using System.Data;
using System.Data.OleDb;
using popLib;

namespace "+_namespace+@"
{
	/// <summary>
	/// Description of DataQuery.
	/// </summary>
	public class DataQuery
	{
		OleDbDataAdapter sqlDataAdapter1;
		OleDbCommand sqlSelectCommand1;
		DataSet ds;
		
				
		public DataQuery(int rowshow, string[] cols, string maintable, string []tablejoin, string condition, string orderby, bool downtoup)
		{
			sqlDataAdapter1 = new OleDbDataAdapter();
			sqlSelectCommand1 = new OleDbCommand();
		
			// sqlDataAdapter1
			sqlDataAdapter1.SelectCommand = sqlSelectCommand1;
			
			// ds
			ds = new DataSet(""DS"" + maintable);
			ds.Tables.Add(maintable);
			
			System.Data.Common.DataColumnMapping[] dcm = new System.Data.Common.DataColumnMapping[cols.Length];
			int i;
			string strSelect = """", strCols = """", strTBJoin = """";
			strSelect = ""SELECT @TOP@ @COLS@ FROM @TABLE@ @JOINTB@"";
			
			for(i=0; i<cols.Length;i++)
			{
				dcm[i] = new System.Data.Common.DataColumnMapping(cols[i], cols[i]);
				if(cols[i].Trim()!=""*"") ds.Tables[0].Columns.Add(cols[i].IndexOf(""."")>0?cols[i].Substring(cols[i].IndexOf(""."")+1):cols[i]);
				strCols += cols[i] + "","";
			}
	
			if(tablejoin!=null) 
			{
				for(i=0; i<tablejoin.Length;i++)
				{
					string[] arrtb = tablejoin[i].Split(':');
					strTBJoin += ""inner join "" + arrtb[0] + "" on "" + maintable + ""."" + arrtb[1] + ""="" + arrtb[0] + ""."" + arrtb[1] + "" "";
				}
				strTBJoin = strTBJoin.Substring(0,strTBJoin.Length-1);
			}
	
			strSelect = strSelect.Replace(""@TOP@"", (rowshow > 0)?(""TOP "" + rowshow):"""");
	
			strSelect = strSelect.Replace(""@COLS@"",strCols.Substring(0,strCols.Length-1));
			strSelect = strSelect.Replace(""@TABLE@"",maintable);
			strSelect = strSelect.Replace(""@JOINTB@"",strTBJoin);
			sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {new System.Data.Common.DataTableMapping(""Table"", maintable, dcm)});
			// sqlSelectCommand1
			strSelect = strSelect + ((condition!=null && condition!="""")?"" where "" + condition:"""");
			if(orderby!=null) strSelect += "" ORDER BY "" + orderby + ((downtoup==true)?"" desc"":"" asc"");
			sqlSelectCommand1.CommandText = strSelect;
			sqlSelectCommand1.Connection = "+_connectionHolder+@".sqlConnection;
		}
		
		public DataQuery(string[] cols, string maintable, string []tablejoin, string condition)
		{
			sqlDataAdapter1 = new OleDbDataAdapter();
			sqlSelectCommand1 = new OleDbCommand();
		
			// sqlDataAdapter1
			sqlDataAdapter1.SelectCommand = sqlSelectCommand1;
			
			// ds
			ds = new DataSet(""DS"" + maintable);
			ds.Tables.Add(maintable);
			
			System.Data.Common.DataColumnMapping[] dcm = new System.Data.Common.DataColumnMapping[cols.Length];
			int i;
			string strSelect = """", strCols = """", strTBJoin = """";
			strSelect = ""SELECT @COLS@ FROM @TABLE@ @JOINTB@"";
			
			for(i=0; i<cols.Length;i++)
			{
				dcm[i] = new System.Data.Common.DataColumnMapping(cols[i], cols[i]);
				if(cols[i].Trim()!=""*"") ds.Tables[0].Columns.Add(cols[i].IndexOf(""."")>0?cols[i].Substring(cols[i].IndexOf(""."")+1):cols[i]);
				strCols += cols[i] + "","";
			}
	
			if(tablejoin!=null) 
			{
				for(i=0; i<tablejoin.Length;i++)
				{
					string[] arrtb = tablejoin[i].Split(':');
					strTBJoin += ""inner join "" + arrtb[0] + "" on "" + maintable + ""."" + arrtb[1] + ""="" + arrtb[0] + ""."" + arrtb[1] + "" "";
				}
				strTBJoin = strTBJoin.Substring(0,strTBJoin.Length-1);
			}
	
			strSelect = strSelect.Replace(""@COLS@"",strCols.Substring(0,strCols.Length-1));
			strSelect = strSelect.Replace(""@TABLE@"",maintable);
			strSelect = strSelect.Replace(""@JOINTB@"",strTBJoin);
	
			sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {new System.Data.Common.DataTableMapping(""Table"", maintable, dcm)});
			// sqlSelectCommand1
			sqlSelectCommand1.CommandText = strSelect + ((condition!=null && condition!="""")?"" where "" + condition:"""");
			sqlSelectCommand1.Connection = "+_connectionHolder+@".sqlConnection;
			
			
		}
		
		public DataQuery(string query)
		{
			ds = new DataSet();
			sqlDataAdapter1   = new OleDbDataAdapter();
			sqlSelectCommand1 = new OleDbCommand();
			sqlSelectCommand1.CommandText = query;
			sqlSelectCommand1.Connection  = "+_connectionHolder+@".sqlConnection;
			sqlDataAdapter1.SelectCommand = sqlSelectCommand1;			
		}
		
		public void ExecuteQuery()
		{
			lock( "+_connectionHolder+@".sqlConnection )
				sqlDataAdapter1.Fill(ds);
		}
		
		public DataSet GetDataSet()
		{
			return ds;
			
		}
		
		public static bool CheckExistRecords(string maintable, string []tablejoin, string condition)
		{
			OleDbCommand sqlSelectCommand2 = new OleDbCommand();
			
			int i;
			string strSelect = """", strTBJoin = """";
			strSelect = ""SELECT @COLS@ FROM @TABLE@ @JOINTB@"";
			
			if(tablejoin!=null) 
			{
				for(i=0; i<tablejoin.Length;i++)
				{
					string[] arrtb = tablejoin[i].Split(':');
					strTBJoin += ""inner join "" + arrtb[0] + "" on "" + maintable + ""."" + arrtb[1] + ""="" + arrtb[0] + ""."" + arrtb[1] + "" "";
				}
				strTBJoin = strTBJoin.Substring(0,strTBJoin.Length-1);
			}
	
			strSelect = strSelect.Replace(""@COLS@"", ""*"");//maintable + ""."" + maintable.Substring(0, maintable.Length - 1) + ""Id"");
			strSelect = strSelect.Replace(""@TABLE@"",maintable);
			strSelect = strSelect.Replace(""@JOINTB@"",strTBJoin);
			
			sqlSelectCommand2.Connection = "+_connectionHolder+@".sqlConnection;
			sqlSelectCommand2.CommandText = strSelect + ((condition!=null && condition!="""")?"" where "" + condition:"""");
			
			"+_connectionHolder+@".sqlConnection.Open();
			bool flag = (sqlSelectCommand2.ExecuteScalar() != null);
			"+_connectionHolder+@".sqlConnection.Close();
			return flag;
		}
		
		public static object GetFirstCell(string column,string maintable, string []tablejoin, string condition)
		{
			OleDbCommand sqlSelectCommand2 = new OleDbCommand();
			
			int i;
			string strSelect = """", strTBJoin = """";
			strSelect = ""SELECT @COLS@ FROM @TABLE@ @JOINTB@"";
			
			if(tablejoin!=null) 
			{
				for(i=0; i<tablejoin.Length;i++)
				{
					string[] arrtb = tablejoin[i].Split(':');
					strTBJoin += ""inner join "" + arrtb[0] + "" on "" + maintable + ""."" + arrtb[1] + ""="" + arrtb[0] + ""."" + arrtb[1] + "" "";
				}
				strTBJoin = strTBJoin.Substring(0,strTBJoin.Length-1);
			}
	
			strSelect = strSelect.Replace(""@COLS@"", column);
			strSelect = strSelect.Replace(""@TABLE@"",maintable);
			strSelect = strSelect.Replace(""@JOINTB@"",strTBJoin);
			
			sqlSelectCommand2.Connection = "+_connectionHolder+@".sqlConnection;
			sqlSelectCommand2.CommandText = strSelect + ((condition!=null && condition!="""")?"" where "" + condition:"""");
			
			"+_connectionHolder+@".sqlConnection.Open();
			object obj = null;
			try
			{
				obj = sqlSelectCommand2.ExecuteScalar();
			}catch{};
			"+_connectionHolder+@".sqlConnection.Close();
			if(obj == null) return """";
			return obj;
		}
		
		public static object GetFirstCell(string maintable, string []tablejoin, string condition)
		{
			string column = maintable + ""."" + maintable + ""_ID"";
			return GetFirstCell(column, maintable, tablejoin, condition);
		}
	
		public static bool execQueryString(string querry){
			OleDbCommand sqlCommand1 = new OleDbCommand();
			sqlCommand1.CommandText = querry;
			sqlCommand1.Connection = "+_connectionHolder+@".sqlConnection;
			"+_connectionHolder+@".sqlConnection.Open();
			int result = sqlCommand1.ExecuteNonQuery();
			"+_connectionHolder+@".sqlConnection.Close();
			return (result==1)?true:false;
		}
		
		static string file_log = FileLib.getFullPath( FileLib.getRandomName( ""Log_"", ""log"" ) );
		public static void DBErrorReport(Exception e, string function)
        {
        	FormLib.alert(  e, function );
        	FileLib.writeLog( file_log, e, function );
        }

	}
}";
			#endregion
		}
	}
}
